package la.bbs558.common;

import com.alibaba.fastjson.serializer.*;

import java.text.DecimalFormat;

/**
 * @author: WeiHanmin
 * @description:
 * @time: 2021-06-01 18:11:57
 */
public class CustomerBigDecimalCodec extends BigDecimalCodec implements ContextObjectSerializer {
    public final static CustomerBigDecimalCodec instance = new CustomerBigDecimalCodec();


    @Override
    public void write(JSONSerializer serializer, Object object, BeanContext context) {
        SerializeWriter out = serializer.out;
        if (object == null) {
            out.writeString("0.00");
            return;
        }
        String format = context.getFormat();
        System.out.println(format);
        DecimalFormat decimalFormat = new DecimalFormat(format);
        out.writeString(decimalFormat.format(object));
    }
}
